package com.usian.article.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.usian.article.feign.AdminFeign;
import com.usian.article.service.ApArticleService;
import com.usian.article.service.HotArticleService;
import com.usian.model.article.pojos.ApArticle;
import com.usian.model.article.vo.HotArticleVO;
import lombok.extern.slf4j.Slf4j;
import org.joda.time.DateTime;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@Slf4j
public class HotArticleServiceImpl implements HotArticleService {

    @Autowired
    private ApArticleService apArticleServiceI;

    @Autowired
    private StringRedisTemplate redisTemplate;

    @Autowired
    private AdminFeign adminFeign;

    @Override
    public void computeHotArticle() {
        // 1.查询出前5天的文章
        String dayParam = DateTime.now().minusDays(5).toString("yyyy-MM-dd 00:00:00");

        List<ApArticle> apArticleList =
                apArticleServiceI.list(Wrappers.<ApArticle>lambdaQuery().gt(ApArticle::getPublishTime, dayParam));
        if (apArticleList == null || apArticleList.isEmpty()) {
            log.info("当前时间前5天没有文章数据：{}", DateTime.now().toString("yyyy-MM-dd 00:00:00"));
            return;
        }
//        // 2.计算文章分值
//        List<HotArticleVO> hotArticleVOList = computeHotArticleScore(apArticleList);
//
//        // 3.按照频道存入redis缓存中
//        cacheAndSort(hotArticleVOList);

    }
}
